package org.testis.data.parser;

import java.util.LinkedHashMap;
import org.orm.PersistentException;
import org.testis.orm.refinedclasses.DynamicMapDesignTreeNode;
import org.testis.utils.middleware.DynamicMap;


/**
 *
 * @author nurhat
 */
public class DynamicMapTreeProviderFactory
{

    private LinkedHashMap<String, DynamicMapDesignTreeNode> designTrees;
    private static DynamicMapTreeProviderFactory provider;


    private DynamicMapTreeProviderFactory()
    {
        designTrees = new LinkedHashMap<String, DynamicMapDesignTreeNode>();
    }


    public static DynamicMapTreeProviderFactory getInstance()
    {
        if (provider == null) {
            provider = new DynamicMapTreeProviderFactory();
        }
        return provider;
    }
     public void clearDynamicMapTrees()
     {
        designTrees.clear();
     }

    public DynamicMapDesignTreeNode getDynamicMapTree(String dutId) throws PersistentException
    {

        DynamicMapDesignTreeNode node = designTrees.get(dutId);
        if (node == null) {
            DynamicMap m_map = DynamicMap.newInstance();

            node = m_map.getDynamicMapDesignTreeFomDB(false,
                                                      Integer.parseInt(dutId));
            designTrees.put(dutId,
                            node);
        }
        return node;
    }
}
